﻿using Modules.System.EarlyWarning;
using PmSoft.Quartz;
using Quartz;

namespace ManagementApi.Jobs
{
    /// <summary>
    /// 项目代发预警记录
    /// </summary>
    [DisallowConcurrentExecution]//不可并行执行
    [JobDescription("0 0 00 10 * ?")]//每月10日00:00:00执行一次
    //[JobDescription("0 */1 * * * ?")]//测试1分钟执行1次
    public class ProjectWageWaringTenHJob : IJob
    {
        private readonly SysEarlyWarningService earlyWarningService;

        public ProjectWageWaringTenHJob(SysEarlyWarningService earlyWarningService)
        {
            this.earlyWarningService = earlyWarningService;
        }

        public Task Execute(IJobExecutionContext context)
        {

            #region 查询上个月项目月报表，代发状态为未落实的数据
            DateTime month = DateTime.Now.AddMonths(-1);
            earlyWarningService.CreateSysEarlyWarning(Convert.ToInt32((month).ToString("yyyyMM")), false);
            #endregion

            #region 查询上上个月项目月报表，代发状态为未落实的数据,并且生成解锁记录
            month = month.AddMonths(-1);
            earlyWarningService.CreateSysEarlyWarning(Convert.ToInt32((month).ToString("yyyyMM")), true);
            #endregion

            return Task.CompletedTask;
        }
    }
}
